﻿Public Class frmElevesSuivi
    Public pListe As String
    Public pNo_ligne As Integer

    Private szSQL As String
    Private rs As ADODB.Recordset

    Private Sub frmElevesSuivi_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        CB_TYPE.Focus()
    End Sub

    Private Sub frmElevesSuivi_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        InitcomboType()
        InitcomboMoyen()
        SuiviToScreen()
    End Sub

    Private Sub InitcomboType()

        ' vider le combo
        CB_TYPE.Items.Clear()
        ' Lire la table CATEGORIES
        szSQL = "CALL spGet_P_TABLES_byCODE('p_types_relance',0)"
        GetRecordset(ctDSN_AEM, szSQL, rs)
        Do While Not rs.EOF
            CB_TYPE.Items.Add(rs.Fields("libelle").Value)
            rs.MoveNext()
        Loop
        ' Close the recordset AND connection.
        rs.Close()

    End Sub

    Private Sub InitcomboMoyen()

        ' vider le combo
        CB_MOYEN.Items.Clear()
        ' Lire la table CATEGORIES
        szSQL = "CALL spGet_P_TABLES_byCODE('p_moyens_relance',0)"
        GetRecordset(ctDSN_AEM, szSQL, rs)
        Do While Not rs.EOF
            CB_MOYEN.Items.Add(rs.Fields("libelle").Value)
            rs.MoveNext()
        Loop
        ' Close the recordset AND connection.
        rs.Close()

    End Sub

    Private Sub SuiviToScreen()

        If pNo_ligne = 0 Then
            ' creation 
            TE_CD_CLI.Text = gCD_CLI
            TE_DATE.Text = Now
            TE_RESULTAT.Clear()
            CB_TYPE.SelectedIndex = 0
            CB_MOYEN.SelectedIndex = 0
        Else
            ' Lire l'enreg sélectionné
            szSQL = "CALL spGet_ELEVES_SUI_byNO_LIGNE('" & pListe & "'," & pNo_ligne & ")"
            GetRecordset(ctDSN_AEM, szSQL, rs)
            If rs.RecordCount > 0 Then
                TE_CD_CLI.Text = rs.Fields("cd_cli").Value
                TE_DATE.Text = rs.Fields("cree_le").Value
                CB_TYPE.SelectedIndex = rs.Fields("type_rel").Value
                CB_MOYEN.SelectedIndex = rs.Fields("moyen_rel").Value
                TE_RESULTAT.Text = nv(rs.Fields("resultat").Value)
                TE_MODIFIE_LE.Text = setModifiedBy(rs.Fields("cree_le").Value, rs.Fields("modif_le").Value, rs.Fields("cd_uti").Value)
            End If
            rs.Close()
        End If

    End Sub

    Private Sub BO_ENREGISTRER_Click(sender As System.Object, e As System.EventArgs) Handles BO_ENREGISTRER.Click

         ' mise à jour 
        szSQL = "CALL spUpd_ELEVES_SUIVI('" & pListe & "'," & pNo_ligne & "," & TE_CD_CLI.Text & "," & CB_TYPE.SelectedIndex & "," & _
            CB_MOYEN.SelectedIndex & ",'" & nq(TE_RESULTAT.Text) & "','" & gUserCode & "')"
        If ExecQuery(ctDSN_AEM, szSQL) Then
            Me.Close()
        End If

    End Sub

    Private Sub BO_SUPPRIMER_Click(sender As System.Object, e As System.EventArgs) Handles BO_SUPPRIMER.Click
        ' utilisateur autorisé à supprimer un suivi ?
        If IsUserAuthorised(9) = False Then
            Exit Sub
        End If
        ' suppression
        If pListe = "SUIVI" Then
            deleteEnregistrement("eleves_sui", TE_DATE.Text, pNo_ligne)
        Else
            deleteEnregistrement("eleves_payeur", TE_DATE.Text, pNo_ligne)
        End If
        Me.Close()
    End Sub
End Class